// src/api/apiService.ts
import axiosInstance from './axiosInstance';

interface ApiResponse<T> {
    data: T;
    status: number;
}

// GET 请求
export const get = async <T>(endpoint: string, params?: Record<string, any>): Promise<ApiResponse<T>> => {
    try {
        const response = await axiosInstance.get<T>(endpoint, { params, withCredentials: false });
        return response;
    } catch (error) {
        throw error;
    }
};

// POST 请求
export const post = async <T>(endpoint: string, data?: Record<string, any>): Promise<ApiResponse<T>> => {
    try {
        const response = await axiosInstance.post<T>(endpoint, data);
        return response;
    } catch (error) {
        throw error;
    }
};

// PUT 请求
export const put = async <T>(endpoint: string, data?: Record<string, any>): Promise<ApiResponse<T>> => {
    try {
        const response = await axiosInstance.put<T>(endpoint, data);
        return response;
    } catch (error) {
        throw error;
    }
};

// DELETE 请求（如果需要）
export const delete = async <T>(endpoint: string, params?: Record<string, any>): Promise<ApiResponse<T>> => {
    try {
        const response = await axiosInstance.delete<T>(endpoint, { params });
        return response;
    } catch (error) {
        throw error;
    }
};
